package com.rockcent.mall.lib.domain;

import com.rockcent.common.domain.IDEntityMall;
import com.rockcent.common.domain.enumclass.Whether;
import com.rockcent.mall.lib.domain.enumclass.CouponDrawLimit;
import com.rockcent.mall.lib.domain.enumclass.MerchantCouponStatus;
import com.rockcent.mall.lib.domain.enumclass.CouponType;
import com.rockcent.mall.lib.domain.enumclass.CouponUseScope;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;

/**
 * Created by oyhk on 16/7/27.
 */
@Entity
@Table(name = "coupon")
@DynamicInsert
@DynamicUpdate
public class MerchantCoupon extends IDEntityMall {
    /**
     * 类型 VOUCHERS("抵用券"), DISCOUNT("折扣券")
     */
    @Column(columnDefinition = "varchar(30) comment '类型 VOUCHERS(\"抵用券\"), DISCOUNT(\"折扣券\")'")
    @Enumerated(EnumType.STRING)
    private CouponType type = CouponType.VOUCHERS;
    /**
     * 名称
     */
    @Column(columnDefinition = "varchar(255) comment '名称'")
    private String name;
    /**
     * 唯一编号
     */
    @Column(columnDefinition = "varchar(255) comment '唯一编号'")
    private String barCode;

    /**
     * 面值(抵用券)
     */
    @Column(columnDefinition = "DECIMAL(30,10) comment '面值(抵用券)'")
    private BigDecimal faceValue;
    /**
     *
     */
    @Column(columnDefinition = "DECIMAL(30,10) comment '享受折扣(折扣券)'")
    private BigDecimal discount;
    /**
     * 最低消费金额
     */
    @Column(columnDefinition = "DECIMAL(30,10) comment '最低消费金额'")
    private BigDecimal limitAmount = BigDecimal.valueOf(0);
    /**
     * 发放数量
     */
    @Column(columnDefinition = "bigint comment '发放数量'")
    private Long quantity;

    /**
     * 剩余数量
     */
    @Column(columnDefinition = "bigint comment '剩余数量'")
    private Long leaveTotal;
    /**
     * 有效期开始时间
     */
    @Column(columnDefinition = "datetime comment '有效期开始时间'")
    private Date dateEnabled;
    /**
     * 有效期结束时间
     */
    @Column(columnDefinition = "datetime comment '有效期结束时间'")
    private Date dateDisabled;
    /**
     * 适用范围
     */
    @Column(columnDefinition = "varchar(30) comment '适用范围 ALL_STORE(\"所有门店\"), ALL_PRODUCT(\"所有产品\"), PART_STORE(\"指定门店\"), PART_PRODUCT(\"指定产品\")'")
    @Enumerated(EnumType.STRING)
    private CouponUseScope useScope = CouponUseScope.ALL_PRODUCT;
    /**
     * 发放时间
     */
    @Column(columnDefinition = "datetime comment '发放时间'")
    private Date dateIssued;
    /**
     * 领取限制
     */
    @Column(columnDefinition = "varchar(30) comment '领取限制 NO(\"没有上限\"), ALL(\"总共上限\"), DAYS(\"每天上限\"), INTEGRATION(\"积分卡券\")'")
    @Enumerated(EnumType.STRING)
    private CouponDrawLimit drawLimit = CouponDrawLimit.NO;
    /**
     * 限制数量
     */
    @Column(columnDefinition = "bigint comment '限制数量'")
    private Long limitCount;
    /**
     * 是否共享
     */
    @Column(columnDefinition = "varchar(30) comment '是否共享 YES(\"是\"), NO(\"否\")'")
    @Enumerated(EnumType.STRING)
    private Whether sharing = Whether.NO;
    /**
     * 是否发布到领券中心
     */
    @Column(columnDefinition = "varchar(30) comment '是否发布到领券中心 YES(\"是\"), NO(\"否\")'")
    @Enumerated(EnumType.STRING)
    private Whether showOnCenter = Whether.NO;
    /**
     * 是否发布到店铺首页
     */
    @Column(columnDefinition = "varchar(30) comment '是否发布到店铺首页 YES(\"是\"), NO(\"否\")'")
    @Enumerated(EnumType.STRING)
    private Whether showOnMerchant = Whether.NO;
    /**
     * LOGO图
     */
    @Column(columnDefinition = "text comment 'LOGO图'")
    private String logoUrl;
    /**
     * 使用说明
     */
    @Column(columnDefinition = "text comment '使用说明'")
    private String introduction;
    /**
     * 状态
     */
    @Column(columnDefinition = "varchar(30) comment '状态 WAIT_ISSUE(\"待发放\"), ISSUED(\"已发放\"), SOLDOUT(\"已下架\"), EXPIRED(\"已过期\"), DELETED(\"已删除\"), UNAUDITED(\"未通过审核\"), WAIT_AUDIT(\"待审核\")'")
    @Enumerated(EnumType.STRING)
    private MerchantCouponStatus status = MerchantCouponStatus.WAIT_ISSUE;
    /**
     * 商家ID
     */
    @Column(columnDefinition = "bigint(20) comment'商家ID'")
    private Long merchantId;
    /**
     * 二维码URL
     */
    @Column(columnDefinition = "varchar(500) comment'二维码URL'")
    private String promoteUrl;
    /**
     * 平台id
     */
    @Column(columnDefinition = "bigint(20) comment'平台id'")
    private Long mallId;
    /**
     * 冻结数量
     */
    @Column(columnDefinition = "bigint(20) comment'冻结数量'")
    private Long quantityFrozen = 0l;
    /**
     * 已使用数量
     */
    @Column(columnDefinition = "bigint(20) comment'已使用数量'")
    private Long quantityUsed = 0l;
    /**
     * 商家名称
     */
    @Column(columnDefinition = "varchar(100) comment'商家名称'")
    private String merchantName;
    /**
     * 积分兑换
     */
    @Column(columnDefinition = "varchar(30) comment '积分兑换 YES(\"是\"), NO(\"否\")'")
    @Enumerated(EnumType.STRING)
    private Whether integration = Whether.NO;
    /**
     * 积分渠道Id
     */
    @Column(columnDefinition = "bigint(20) comment'积分渠道Id'")
    private Long integrationChannelId;

    /**
     * 投放批次号
     */
    @Column(columnDefinition = "bigint comment '投放批次号'")
    private Long batchPutNo;

    public static final String PRODUCT_ID_IS_NOT_NULL = "产品ID 不能为空";

    public CouponType getType() {
        return type;
    }

    public void setType(CouponType type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public BigDecimal getFaceValue() {
        return faceValue;
    }

    public void setFaceValue(BigDecimal faceValue) {
        this.faceValue = faceValue;
    }

    public String getPromoteUrl() {
        return promoteUrl;
    }

    public void setPromoteUrl(String promoteUrl) {
        this.promoteUrl = promoteUrl;
    }

    public BigDecimal getDiscount() {
        return discount;
    }

    public void setDiscount(BigDecimal discount) {
        this.discount = discount;
    }

    public BigDecimal getLimitAmount() {
        return limitAmount;
    }

    public void setLimitAmount(BigDecimal limitAmount) {
        this.limitAmount = limitAmount;
    }

    public Long getQuantity() {
        return quantity;
    }

    public void setQuantity(Long quantity) {
        this.quantity = quantity;
    }

    public Date getDateEnabled() {
        return dateEnabled;
    }

    public void setDateEnabled(Date dateEnabled) {
        this.dateEnabled = dateEnabled;
    }

    public Long getLeaveTotal() {
        return leaveTotal;
    }

    public void setLeaveTotal(Long leaveTotal) {
        this.leaveTotal = leaveTotal;
    }

    public Date getDateDisabled() {
        return dateDisabled;
    }

    public void setDateDisabled(Date dateDisabled) {
        this.dateDisabled = dateDisabled;
    }

    public CouponUseScope getUseScope() {
        return useScope;
    }

    public void setUseScope(CouponUseScope useScope) {
        this.useScope = useScope;
    }

    public String getBarCode() {
        return barCode;
    }

    public void setBarCode(String barCode) {
        this.barCode = barCode;
    }

    public Date getDateIssued() {
        return dateIssued;
    }

    public void setDateIssued(Date dateIssued) {
        this.dateIssued = dateIssued;
    }

    public CouponDrawLimit getDrawLimit() {
        return drawLimit;
    }

    public void setDrawLimit(CouponDrawLimit drawLimit) {
        this.drawLimit = drawLimit;
    }

    public Long getLimitCount() {
        return limitCount;
    }

    public void setLimitCount(Long limitCount) {
        this.limitCount = limitCount;
    }

    public Whether getSharing() {
        return sharing;
    }

    public void setSharing(Whether sharing) {
        this.sharing = sharing;
    }

    public Whether getShowOnCenter() {
        return showOnCenter;
    }

    public void setShowOnCenter(Whether showOnCenter) {
        this.showOnCenter = showOnCenter;
    }

    public Whether getShowOnMerchant() {
        return showOnMerchant;
    }

    public void setShowOnMerchant(Whether showOnMerchant) {
        this.showOnMerchant = showOnMerchant;
    }

    public String getLogoUrl() {
        return logoUrl;
    }

    public void setLogoUrl(String logoUrl) {
        this.logoUrl = logoUrl;
    }

    public String getIntroduction() {
        return introduction;
    }

    public void setIntroduction(String introduction) {
        this.introduction = introduction;
    }

    public MerchantCouponStatus getStatus() {
        return status;
    }

    public void setStatus(MerchantCouponStatus status) {
        this.status = status;
    }

    public Long getMerchantId() {
        return merchantId;
    }

    public void setMerchantId(Long merchantId) {
        this.merchantId = merchantId;
    }

    public Long getMallId() {
        return mallId;
    }

    public void setMallId(Long mallId) {
        this.mallId = mallId;
    }

    public Long getQuantityFrozen() {
        return quantityFrozen;
    }

    public void setQuantityFrozen(Long quantityFrozen) {
        this.quantityFrozen = quantityFrozen;
    }

    public Long getQuantityUsed() {
        return quantityUsed;
    }

    public void setQuantityUsed(Long quantityUsed) {
        this.quantityUsed = quantityUsed;
    }

    public String getMerchantName() {
        return merchantName;
    }

    public void setMerchantName(String merchantName) {
        this.merchantName = merchantName;
    }

    public Whether getIntegration() {
        return integration;
    }

    public void setIntegration(Whether integration) {
        this.integration = integration;
    }

    public Long getIntegrationChannelId() {
        return integrationChannelId;
    }

    public void setIntegrationChannelId(Long integrationChannelId) {
        this.integrationChannelId = integrationChannelId;
    }


    public Long getBatchPutNo() {
        return batchPutNo;
    }

    public void setBatchPutNo(Long batchPutNo) {
        this.batchPutNo = batchPutNo;
    }

    @Override
    public String toString() {
        return "MerchantCoupon{" +
                "type=" + type +
                ", name='" + name + '\'' +
                ", barCode='" + barCode + '\'' +
                ", faceValue=" + faceValue +
                ", discount=" + discount +
                ", limitAmount=" + limitAmount +
                ", quantity=" + quantity +
                ", leaveTotal=" + leaveTotal +
                ", dateEnabled=" + dateEnabled +
                ", dateDisabled=" + dateDisabled +
                ", useScope=" + useScope +
                ", dateIssued=" + dateIssued +
                ", drawLimit=" + drawLimit +
                ", limitCount=" + limitCount +
                ", sharing=" + sharing +
                ", showOnCenter=" + showOnCenter +
                ", showOnMerchant=" + showOnMerchant +
                ", logoUrl='" + logoUrl + '\'' +
                ", introduction='" + introduction + '\'' +
                ", status=" + status +
                ", merchantId=" + merchantId +
                ", promoteUrl='" + promoteUrl + '\'' +
                ", mallId=" + mallId +
                ", quantityFrozen=" + quantityFrozen +
                ", quantityUsed=" + quantityUsed +
                ", merchantName='" + merchantName + '\'' +
                ", integration=" + integration +
                ", integrationChannelId=" + integrationChannelId +
                ", batchPutNo=" + batchPutNo +
                '}';
    }
}
